<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #dept_id="{ record }">
        <!-- 对标题加上 tag -->
        <a-tag color="blue">{{ record?.dept?.name }}</a-tag>
      </template>
      <template #contract_id="{ record }">
        <!-- 对标题加上 tag -->
        <a-tag color="blue">{{ record?.contract?.name }}</a-tag>
      </template>
      <template #goods_id="{ record }">
        <!-- 对标题加上 tag -->
        <a-tag color="blue">{{ record?.goods?.name }}</a-tag>
      </template>
      <template #operationAfterExtend="{ record }">
        <a-popconfirm content="是否删除此条信息?" @ok="handleDel(record)">
            <a-link  >删除</a-link>
        </a-popconfirm>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemUserContractGoods from '@/api/system/systemUserContractGoods'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const contract_id = ref()
const inforow = ref()
const open = (row) => {
  contract_id.value = row.id
  inforow.value = row
  crudRef.value.requestData()
}


const handleDel = (row) =>{  // 删除
  systemUserContractGoods.deletes({id:row.id}).then(res=>{
    if(res.code == 200){
      Message.success('删除成功')
      crudRef.value.refresh()
    }
  })
}


const numberOperation = (newValue, id, numberName) => {
  systemUserContractGoods.numberOperation({ id, numberName, numberValue: newValue }).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => { console.log(e) })
}

const switchStatus = (statusValue, id, statusName) => {
  systemUserContractGoods.changeStatus({ id, statusName, statusValue }).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => { console.log(e) })
}


const options = reactive({
  id: 'flyos_system_user_contract_goods',
  // rowSelection: {
  //   showCheckedAll: true
  // },
  bordered: { cell: true },
  showTools: false,
  showIndex: false,
  expandSearch: false,
  operationColumn: false,
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 800
  },
  api: systemUserContractGoods.getList,
  recycleApi: systemUserContractGoods.getRecycleList,
  add: {
    show: true,
    api: systemUserContractGoods.save,
    auth: ['system:userContractGoods:save']
  },
  edit: {
    show: true,
    api: systemUserContractGoods.update,
    auth: ['system:userContractGoods:update']
  },
  delete: {
    show: false,
    api: systemUserContractGoods.deletes,
    auth: ['system:userContractGoods:delete'],
    realApi: systemUserContractGoods.realDeletes,
    realAuth: ['system:userContractGoods:realDeletes']
  },
  recovery: {
    show: true,
    api: systemUserContractGoods.recoverys,
    auth: ['system:userContractGoods:recovery']
  },
  import: {
    show: false,
    url: 'system/userContractGoods/import',
    templateUrl: 'system/userContractGoods/downloadTemplate',
    auth: ['system:userContractGoods:import']
  },
  export: {
    show: false,
    url: 'system/userContractGoods/export',
    auth: ['system:userContractGoods:export']
  },
  beforeRequest: (params) => {
    params.contract_id = contract_id.value
    params.order = 'created_at'
    params.orderType = 'desc'
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: '合同公司',
    dataIndex: 'dept_id',
    addDefaultValue: async function () {
      return inforow.value.dept_id;
    },
    disabled: true,
    align: "center",
    formType: 'select',
    search: true,
    dict: {
      
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: 'system/dept/remote',
      // 指定组件接收的props
      props: { label: 'name', value: 'id' },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ['id', 'name'],
        // 设置数据过滤as
        filter: {
          type: ['=', 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [

        ]
      }
    },
  },
  {
    title: '合同名称',
    dataIndex: 'contract_id',
    align: "center",
    addDefaultValue: async function () {
      return inforow.value.id;
    },
    disabled: true,
    formType: 'select',
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: 'system/userContract/remote',
      // 指定组件接收的props
      props: { label: 'name', value: 'id' },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ['id', 'name'],
        // 设置数据过滤
        filter: {

        },
        // 关联模型
        relations: [

        ]
      }
    },
    commonRules: {
      required: true,
      message: "请选择合同名称"
    }
  },
  {
    title: '品名',
    dataIndex: 'goods_id',
    align: "center",
    formType: 'select',
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: 'goods/manage/remote',
      // 指定组件接收的props
      props: { label: 'name', value: 'id' },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ['id','name'],
        // 设置数据过滤
        filter: {

        }, 
        // 关联模型
        relations: [

        ]
      }
    }
  },
   
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "range",
    align: "center",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
defineExpose({ open })
</script>
<script>
export default { name: 'system:userContractGoods' } </script>